// @flow
/* const obj = {
    foo: 'value1',
    bar: 'value2'
}
console.log(Object.entries(obj))


function ajax (a) {
    return new Promise(function (resolve, reject) {
        setTimeout(() => {
            resolve({name: a})
        }, 1000)
    })
}

function * main () {
    const users = yield ajax(123)
    console.log(users)
    const users1 = yield ajax(12333)
    console.log(users1)
}

const g = main()

const result = g.next()
result.value.then(data => {
    const result2 = g.next(data)
    result2.value.then(data1 => {
        const result2 = g.next(data1)
    })
}) */

/* const name = 'Jack'
const gender = 'man'
function myTagFunc (strings, a, b) {
    return strings[0] + a + strings[1] + b + strings[2]
}
const result = myTagFunc`hey, ${name} is a ${gender}.`
console.log(result)

this.name='asdfa'
const person = {
    name: 'tom',
    sayHi: () => {{
        console.log(this)
        console.log(`hi, my name is ${this.name}`)
    }}
}
const obj = {
    name: '123',
    bm: person
}
obj.bm.sayHi() */

/* const person = {
    name: 'cs',
    age: 19
}
const personProxy = new Proxy(person, {
    deleteProperty (target, property) {
        console.log('delete', property)
    },
    has (target, property) {
        console.log('has', property)
    },
    get (target, property) {
        //return Reflect.get(target, property)
        return property in target ? target[property] : undefined
        console.log(target, property)
        return 100 
    },
    set (target, property, value) {
        if (property === 'age') {
            if (!Number.isInteger(value)) {
                throw new TypeError(value + ' is not an int')
            }
        }
        target[property] = value
        //console.log(target, property, value)
    }
}) */
//personProxy.age = 33
//console.log(personProxy.name)
//console.log(personProxy.age)

//delete personProxy.age
//'age' in personProxy
/* function Student (name) {
    this.name = name
}
Student.prototype.say = function () {
    console.log('hi, my name is ' + this.name)
}
let x = new Student('hh')
x.say() */

/* const list = []

const listProxy = new Proxy(list, {
    set (target, property, value) {
        console.log('set', property, value)
        target[property] = value
        return true
    }
})

listProxy.push(100) */

/* const map = new Map()
map.set({name: 'tom'}, 90)
map.set([1], 111)
//console.log(map)

map.forEach((value, key) => {
    console.log(key, value)
})

for (const iterator of map) {
    console.log(iterator)
} */

/* console.log(Symbol('foo'))

const obj = {
    [Symbol()]: 1,
    [Symbol()]: 2,
}

console.log(Symbol.for('1') === Symbol.for(1)) */


/* const obj = {
    store: ['foo', 'bar', 'baz'],
    [Symbol.iterator]: function * () {
        for (const item of this.store) {
            yield item
        }
    }
    [Symbol.iterator]: function () {
        let index = 0
        const self = this
        return {
            next: function () {
                const result = {
                    value: self.store[index],
                    done: index >= self.store.length
                }
                index++
                return result
            }
        }
    } 
} */
/* for (const item of obj) {
    console.log(item)
}
 */
/* function sum (a:number,b) {
    return a + b
}

sum('100', 100)

const a: string = 'sdf'
const b: number = NaN
const c: boolean = false
const d: null = null
const e: void = undefined
const f: symbol = Symbol()
 */


/*  async function async1() {
     console.log('async1 start')
     await async2()
     console.log('async1 ...')
     await async3()
     console.log('async1 end')
 }
async function async2() {
    console.log('async2')
}
async function async3() {
    console.log('async3')
}
console.log('start')

setTimeout(function () {
    console.log('setTimeout')
}, 0)

async1()

new Promise(function(resolve) {
    console.log('promise1');
    resolve();
}).then(function() {
    console.log('promise2');
}).then(function() {
    console.log('promise3');
});;

console.log('end') */

/* new Promise((resolve, reject) => {
    console.log(1)
    resolve()
    return new Promise((res, re) => {
        setTimeout(() => {
            console.log(2)
        }, 0)
        res()
    }).then(() => {
        setTimeout(() => {
            console.log(3)
        }, 0)
    })
}).then(() => {
    console.log(4)
}).then(() => {
    console.log(5)
}) */


new Promise(resolve => {
    console.log("Promise"); 
    resolve();
  })
.then(function() {
    new Promise(resolve => {
        console.log("promise1");
        resolve();
    })
    .then(function() {
        console.log("promise1-1");
    })
    .then(function() {
        console.log("promise1-2");
    })
    console.log("after promise1");
})
.then(function() {
    new Promise(resolve => {
        console.log("promise2");
        resolve();
    })
    .then(function() {
        console.log("promise2-1");
    })
    .then(function() {
        console.log("promise2-2");
    })
    console.log("after promise2");
})
.then(function() {
    new Promise(resolve => {
        console.log("promise3");
        resolve();
    })
    .then(function() {
        console.log("promise3-1");
    })
    .then(function() {
        console.log("promise3-2");
    })
    console.log("after promise3");
});